package com.zd.controller;/**
 * @Description: WaybilllistController
 * @Author:pioneer
 * @Date: 2021-06-25
 * @Version:v1.0
 */

import com.zd.service.lnter.*;
import com.zzg.entity.Tailafter;
import com.zzg.entity.Waybilllist;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: WaybilllistController控制器
 * @Author:pioneer
 * @Date: 2021-06-25
 * @Version:v1.0
 */
@Controller
public class WaybilllistController {

    @Autowired
    private WaybilllistServicelnter waybillServicelnter;
    @Autowired
    private TailafterServicelnter tailafterServicelnter;
    @Autowired
    private WaybillServicelnter waybilllnter;
    @Autowired
    private FreightinformationServicelnter freigServicelnter;
    @Autowired
    private TransportProtocolServicelnter transportServicelnter;

    @RequestMapping("waybillqueryzd.action")
    @ResponseBody
    public Map<String,Object> waybillquery(int page,int limit){
        System.out.println ("正在用waybillquery进行查询");
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",waybillServicelnter.querywaybill ().size ());
        map.put("data",waybillServicelnter.getpaging (page,limit));
        System.out.println (map);
        return map;
    }

    @RequestMapping("conditionzd.action")
    @ResponseBody
    public Map<String,Object> conditionalquery(String consignmentid, String consignmentdate, String commitmentdate, String origin, String arrivestation, String getcity, String forwardingunit, String receivingunit, String transportid, String transportCarid, String waybillstatus){
        System.out.println ("正在用conditionalquery进行条件查询");
        System.out.println (consignmentid);
        int page=1;
        int limit=10;
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",waybillServicelnter.dynamicquery (consignmentid,consignmentdate,commitmentdate,origin,arrivestation,getcity,forwardingunit,receivingunit,transportid,transportCarid,waybillstatus).size ());
        map.put("data",waybillServicelnter.conditionalquery (consignmentid,consignmentdate,commitmentdate,origin,arrivestation,getcity,forwardingunit,receivingunit,transportid,transportCarid,waybillstatus,page,limit));
        System.out.println (map);
        return map;
    }

    @RequestMapping("idqueryzd.action")
    @ResponseBody
    public Map<String, Waybilllist> idquery(String consignmentid){
        System.out.println ("正在用idquery进行查询");
        Waybilllist waybilllist=waybillServicelnter.idquery (consignmentid);
        System.out.println ("id===="+consignmentid);
        Map<String, Waybilllist> map=new HashMap<> ();
        map.put ("Waybilllist",waybilllist);
        System.out.println (map);
        return map;
    }

    @RequestMapping("addtailafter.action")
    public void addtailafter(Tailafter tailafter, HttpServletResponse response) throws IOException {
        System.out.println ("正在用addtailafter进行跟踪新增");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int ser=tailafterServicelnter.increasetailafter (tailafter);
       if(ser>0){
           out.write ("添加成功");
       }else {
           out.write ("添加失败");
       }
       out.close ();
    }

    @RequestMapping("getTailafter.action")
    @ResponseBody
    public Map<String, Tailafter> getTailafter(String consignmentid, HttpServletResponse response){
        System.out.println ("正在用getTailafter进行新增跟踪");
        Tailafter tailafter=tailafterServicelnter.idquery (consignmentid);
        Map<String, Tailafter> map=new HashMap<> ();
        if(tailafter==null){
            Tailafter tailafter1=new Tailafter ();
            tailafter1.setWaybillId (consignmentid);
            map.put ("Tailafter",tailafter1);
        }else {
            map.put ("Tailafter",tailafter);
        }
        System.out.println (map);
        return map;
    }
    @RequestMapping("delectwaybill.action")
    public void delectwaybill(String consignmentid,HttpServletResponse response) throws IOException {
        System.out.println ("正在用delectwaybill进行删除");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        System.out.println ("id=========="+consignmentid);
        if(consignmentid!=null){
            int sre=transportServicelnter.delectagreement (consignmentid);
            int res=freigServicelnter.deletefreightInformation (consignmentid);
            out.write("删除成功");
        }
    }

}
